<#--菜单权限tree-->
<div id="menuPermissionTree" class="tree">
    <div class="tree-folder" style="display: none;">
        <div class="tree-folder-header">
            <i class="fa fa-folder palegreen"></i>
            <div class="tree-folder-name"></div>
        </div>
        <div class="tree-folder-content"></div>
        <div class="tree-loader" style="display: none;"></div>
    </div>
    <div class="tree-item" style="display: none;">
        <i class="tree-dot"></i>
        <div class="tree-item-name"></div>
    </div>
</div>
<script type="text/javascript">
    <!--
    var AjaxDataSourceTree = function (options) {
        this._data = options.data;
        this._delay = options.delay;
        this._loadData = options.loadData;
        this._isInit = false;
    };
    AjaxDataSourceTree.prototype = {
        data: function (options, callback) {
            if (options.params && options.params.uuid) {
                console.log(options.params.uuid);
            }
            var self = this;
            if (self._isInit && self._loadData
                    && (typeof self._loadData === "function")) {
                self._loadData(options, function (data) {
                    if (!data) {
                        data = [];
                    }
                    callback({
                        data: data
                    });
                });
            } else {
                setTimeout(function () {
                    var data = $.extend(true, [], self._data);
                    var childrenData = options.data;
                    if (childrenData) {
                        if (childrenData.length > 0) {
                            data = childrenData;
                        } else {
                            data = [];
                        }
                    }
                    callback({
                        data: data
                    });
                    self._isInit = true;
                }, this._delay);
            }
        }
    };
    /**
     * 延迟加载菜单权限
     */
    function loadAjaxTree(treeId, pId, setDataCallback) {
        var url = "permissionSetting/getMenuPermissions.do?checkedCallback=${checkedCallback[0]}&permissionDetailCallback=${permissionDetailCallback[0]}&objType=${objType[0]}&objId=${objId[0]}";
        if (!pId) {
            pId = "";
        }
        var params = {
            pId: pId
        };
        ajaxRequest(url, params, function (data) {
            if (data.resCode == "200") {
                var treeData = eval("(" + data.data + ")");
                console.log(treeData);
                if (setDataCallback && (typeof setDataCallback === "function")) {
                    setDataCallback(treeData);
                } else {
                    var menuPermissionTreeAjaxDataSourceTree = new AjaxDataSourceTree({
                        data: treeData,
                        delay: 100,
                        loadData: function (option, callback) {
                            var pId = "";
                            console.log(option.params);
                            if (option.params && option.params.id) {
                                pId = option.params.id;
                            }
                            loadAjaxTree(treeId, pId, callback);
                        }
                    });
                    $("#" + treeId).tree({
                        cacheItems: true,
                        selectable: false,
                        multiSelect: false,
                        dataSource: menuPermissionTreeAjaxDataSourceTree,
                        loadingHTML: '<div class="tree-loading"><i class="fa fa-rotate-right fa-spin"></i></div>'
                    });
                }
            } else {
                ajaxError(data.resMsg);
            }
        },
        function (XMLHttpRequest, textStatus, errorThrown) {
            ajaxError(errorThrown);
        }, "GET", "JSON");
    }
    //-->
</script>
